package com.mdlaser.service.impl;

import com.mdlaser.dto.Commodity;
import com.mdlaser.entity.WishLanguage;
import com.mdlaser.entity.WishType;
import com.mdlaser.mapper.WishTypeMapper;
import com.mdlaser.service.IWishLanguageService;
import com.mdlaser.service.IWishTypeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author mdlaser
 * @since 2024-05-16
 */
@Service
public class WishTypeServiceImpl extends ServiceImpl<WishTypeMapper, WishType> implements IWishTypeService {
    @Autowired
    IWishLanguageService wishLanguageService;

    @Override
    public List<Commodity> getCommodity() {
        List<WishType> wishTypes = this.getBaseMapper().selectList(null);
        ArrayList<Commodity> result = new ArrayList<>();
        for (WishType wishType : wishTypes) {
            Commodity commodity = new Commodity();
            BeanUtils.copyProperties(wishType, commodity);
            List<WishLanguage> wishLanguages = wishLanguageService.selectByWishId(wishType.getWishId());
            commodity.setLanguages(wishLanguages);
            result.add(commodity);
        }
        return result;
    }
}
